package com.ruoyi.system.controller;

import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.LongVideo;
import com.ruoyi.system.service.ILongVideoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 长视频管理Controller
 *
 * @author ruoyi
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/video")
public class LongVideoController extends BaseController
{
    @Autowired
    private ILongVideoService longVideoService;

    @Autowired
    private RedisTemplate redisTemplate;



//    图片处理
    /**
     * 查询长视频管理列表
     */
    @RequiresPermissions("system:video:list")
    @GetMapping("/list")
    public TableDataInfo list(LongVideo longVideo)
    {
        startPage();
        List<LongVideo> list = longVideoService.selectLongVideoList(longVideo);
        return getDataTable(list);
    }

    /**
     * 导出长视频管理列表
     */
    @RequiresPermissions("system:video:export")
    @Log(title = "长视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LongVideo longVideo)
    {
        List<LongVideo> list = longVideoService.selectLongVideoList(longVideo);
        ExcelUtil<LongVideo> util = new ExcelUtil<LongVideo>(LongVideo.class);
        util.exportExcel(response, list, "长视频管理数据");
    }

    /**
     * 获取长视频管理详细信息
     */
    @RequiresPermissions("system:video:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
       LongVideo longVideo= longVideoService.selectLongVideoById(id);
        return success(longVideo);
    }


    /**
     * 根据长视频id查询长视频信息
     */
    @GetMapping(value = "/getInfoByLongId/{longId}")
    public AjaxResult getInfoByLongId(@PathVariable("longId") Integer longId){
        List<LongVideo> longVideos = longVideoService.selectLongVideoByLongId(longId);
        return success(longVideos);
    }



    /**
     * 新增长视频管理
     */
    @RequiresPermissions("system:video:add")
    @Log(title = "长视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LongVideo longVideo)
    {
        longVideo.setStatus(1);
        longVideo.setUploader("admin");
        longVideo.setIpone("1888552588");
        longVideo.setStart(1);
        longVideo.setAudit("雷*");
        longVideo.setTime(new Date());
        longVideo.setEnd(new Date());
        longVideo.setContentId("GGHH77788");

        longVideo.setLongId(1);
        return toAjax(longVideoService.insertLongVideo(longVideo));
    }

    /**
     * 修改长视频管理
     */
    @RequiresPermissions("system:video:edit")
    @Log(title = "长视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LongVideo longVideo)
    {
        if (longVideo.getStart()==1){
            return toAjax(longVideoService.updateLongVideo(longVideo));
        }else {
            longVideo.setStatus(1);
            redisTemplate.opsForValue().set("longVideo", longVideo);
            return toAjax(longVideoService.updateLongVideo(longVideo));
        }

    }

    /**
     * 删除长视频管理
     */
    @RequiresPermissions("system:video:remove")
    @Log(title = "长视频管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(longVideoService.deleteLongVideoByIds(ids));
    }



}
